#ifndef __DOUBLELINKLIST_H_
#define __DOUBLELINKLIST_H_

#include<cstddef>
#include <iostream>


class DoubleLinkList
{
public:
    using ElementType = void *;
    DoubleLinkList();
    //拷贝构造  赋值运算符重载
    DoubleLinkList(const DoubleLinkList& list);
    DoubleLinkList& operator=(const DoubleLinkList& list);

    ~DoubleLinkList();

    void InsertTail(const ElementType& element);

    void InsertByIndex(size_t index, const ElementType& element);

    size_t Size()
    {
        return this->size;
    }
    //删除2个
    void RemoveByIndex(size_t index);
    void RemoveByElement(const ElementType& element);
    //查找2个
    ElementType* FindByIndex(size_t index);
    //DARRAY::DynamicArray FindeByElement(const ElementType& element);
    //修改2个
    void UpdataByIndex(size_t index,const ElementType& element);
    void UpdataByElement(const ElementType& oldValue,const ElementType& newValue);
    //排序  快速排序
    void Sort();

    void show();

    void SetFreeFunc(void (*Free)(void *))
    {
        this->Free = Free;
    }

    void SetPrintFunc(void (*Print)(void *))
    {
        this->Print = Print;
    }

    void SetCompareFunc(bool (*Compare)(void *, void *))
    {
        this->Compare = Compare;
    }
    
    void SetGreaterFunc(bool (*Greater)(void *, void *))
    {
        this->Greater = Greater;
    }

    void SetCopyDataFunc(ElementType (*CopyData)(void *))
    {
        this->CopyData = CopyData;
    }

private:
    struct Node
    {
        Node(const ElementType& value)
        {
            this->value = value;
            next = prev = nullptr;
        }

        ElementType value;
        Node *next;//后驱指针
        Node *prev;//前驱指针
    };
    void FastSort(Node *start, Node *end);
    Node *head;
    Node *tail;
    size_t size;

    void (*Free)(void *);   //释放对象
    bool (*Compare)(void *, void *);    //比较大小
    void (*Print)(void *);  //打印
    bool (*Greater)(void *, void *);    //大于
    ElementType (*CopyData)(void *);   //拷贝内容
};

#endif